package com.example.restaurantclient.Activity;



import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;

import androidx.fragment.app.Fragment;

import com.example.restaurantclient.Fragment.WelcomePageFragment.FirstFragment;
import com.example.restaurantclient.Fragment.WelcomePageFragment.SecondFragment;
import com.example.restaurantclient.Fragment.WelcomePageFragment.ThirdFragment;
import com.example.restaurantclient.R;
import com.github.appintro.AppIntro;
import com.github.appintro.AppIntroPageTransformerType;

import org.jetbrains.annotations.Nullable;

public class AppIntroActivity extends AppIntro {
    private SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        sharedPreferences=this.getSharedPreferences(
                "app", Context.MODE_PRIVATE);
        boolean isfirst=sharedPreferences.getBoolean("first_open",true);
        Log.e("222222",isfirst+"");
        //判断是否第一次启动
        if (isfirst){
            addSlide(new FirstFragment());
            addSlide(new SecondFragment());
            addSlide(new ThirdFragment());
            //设置淡出过渡
            //setTransformer(AppIntroPageTransformerType.Fade.INSTANCE);
            setTransformer(AppIntroPageTransformerType.Zoom.INSTANCE);
            // 显示/隐藏跳过按钮
            setSkipButtonEnabled(true);
            setVibrateDuration(2000);
            setVibrate(false);
        }else{
            Intent intent=new Intent(this,LoginActivity.class);
            startActivity(intent);
            finish();
        }
    }

    @Override
    protected void onSkipPressed(@Nullable Fragment currentFragment) {
        super.onSkipPressed(currentFragment);

       //当执行跳过动作时触发
        Intent intent=new Intent(this,FragmentActivity.class);
        startActivity(intent);

        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("first_open",false);
        editor.commit();
        finish();
    }

    @Override
    protected void onDonePressed(@Nullable Fragment currentFragment) {
        super.onDonePressed(currentFragment);
        //执行完成动作时触发
        Intent intent=new Intent(this,FragmentActivity.class);
        startActivity(intent);

        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("first_open",false);
        editor.commit();
        finish();
    }
}